package robomind;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


/**
 *
 * @author luisorozco
 */
import javax.microedition.lcdui.*;

public class Imagen extends Canvas implements CommandListener {
private MoverImagen midlet;
private Image im;
private Command salir; 
private int x, y;
public Imagen(MoverImagen mid){
    salir = new Command("Salir",Command.EXIT,1);
    this.midlet = mid;
    this.addCommand(salir); 
    this.setCommandListener(this);
    try{
    im = Image.createImage("/robomind/dibujo3.jpeg"); }
    catch (Exception e)
    {
    System.out.println("Error al cargar archivo de imagen");
    }
    x = 0; 
    y = 0;
    }

public void paint(Graphics g) {
    g.setColor(255,255,255); 
    g.fillRect(0,0,getWidth(),getHeight());
    g.setColor(3,3,5);
    g.drawImage(im,x,y,Graphics.TOP|Graphics.LEFT); 
}

protected void keyPressed(int keyCode)
{ 
switch(getGameAction(keyCode)){
case Canvas.DOWN: { 
    if ((y+15)<getHeight()) y = y+25; 
    break; 
}
case Canvas.LEFT: { 
    if (x > 0) x = x-25; 
    break;
}
case Canvas.UP: { 
    if (y > 0) y = y-25; 
    break;
}
case Canvas.RIGHT:{ 
    if ((x+15) < getWidth()) x = x+25; 
    break;
}
}
this.repaint(); }
public void commandAction(Command c, Displayable d)
{ 
    if (c == salir){
    midlet.salir(); 
        }
    } 
}
